package com.example.listening.examsdk.core;

import android.text.TextUtils;

import com.example.listening.examsdk.ExamSDK;

import org.json.JSONObject;

import java.io.File;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by tong on 15/12/15.
 */
public class Section implements Serializable {
    //    "Section A": {
//        "Txt": "听对话,从下面各题所给的A、B、C三幅图片中选择与对话内容相符的图片。每段对话读两遍",
//                "Sound": "Z1_A.mp3",
//                "Q1": "Q21_1_1_000011",
//                "Q2": "Q21_1_1_000012",
//                "Q3": "Q21_1_1_000013",
//                "Q4": "Q21_1_1_000014",
//                "Q5": "Q21_1_1_000015"
//    }
    private String lessonId;

    private String txt;

    private String sound;

    private String name;

    public Section(String sectionName, JSONObject sectionObj) {
        this.name = sectionName;
        this.txt = sectionObj.optString("Txt");
        this.sound = sectionObj.optString("Sound");
    }

    public String getName() {
        return this.name;
    }

    public String getTxt() {
        return txt;
    }

    public File getSoundFile() {
        if (TextUtils.isEmpty(sound)) {
            return null;
        }
        String path = ExamSDK.getPathStrategy().getFreeSubjectRelativePath(ExamSDK.FREE_DIR_NAME);
        File file = new File(ExamSDK.getPathStrategy().getRootPath(),path + "/" + sound);
        return file;
    }

    public List<MediaItem> getAllMediaItem() {
        List<MediaItem> fileList = new ArrayList<MediaItem>();
        File file = getSoundFile();
        if (file != null) {
            fileList.add(new MediaItem(file));
        }
        return fileList;
    }

    @Override
    public String toString() {
        return "Section{" +
                "lessonId='" + lessonId + '\'' +
                ", txt='" + txt + '\'' +
                ", sound='" + sound + '\'' +
                ", name='" + name + '\'' +
                '}';
    }

//    @Override
//    public boolean equals(Object o) {
//        if (this == o) return true;
//        if (o == null || getClass() != o.getClass()) return false;
//
//        Section section = (Section) o;
//
//        return !(name != null ? !name.equals(section.name) : section.name != null);
//
//    }
//
//    @Override
//    public int hashCode() {
//        return name != null ? name.hashCode() : 0;
//    }
}
